// Package xerr @Author wesley 2023/6/13 16:31:00
package xerr

import "fmt"

type CodeError struct {
	code   int
	errMsg string
}

// GetErrCode 返回给前端的错误码
func (e *CodeError) GetErrCode() int {
	return e.code
}

// GetErrMsg 返回给前端显示的错误信息
func (e *CodeError) GetErrMsg() string {
	return e.errMsg
}

func (e *CodeError) Error() string {
	return fmt.Sprintf("ErrCode:%d, ErrorMsg:%s", e.code, e.errMsg)
}

func NewErrCodeMsg(errCode int, errMsg string) *CodeError {
	return &CodeError{code: errCode, errMsg: errMsg}
}
func NewErrCode(errCode int) *CodeError {
	return &CodeError{code: errCode, errMsg: MapErrMsg(errCode)}
}

func NewErrMsg(errMsg string) *CodeError {
	return &CodeError{code: ServerError, errMsg: errMsg}
}
